package com.mall.hadoop.job.tfirstgardenstatistics;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
/**
 * 全国圆所统计省、市、区
 * @author liugb
 *
 */
public class FirstLoginTimeReduce extends Reducer<Text, IntWritable, Text, IntWritable>{

	@Override
	protected void reduce(Text key, Iterable<IntWritable> value,Context context) throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		try {
			int province = 0;
			int city = 0;
			int area = 0;
			int counttime = 0;
			String k = key.toString();
			for (IntWritable vs : value) {
//				//同一省（包括管辖的市、区）
//				if(k.contains("zh_zh")||k.contains("xh_xh")||k.contains("mh_fh")){
//					province += vs.get();
//				}
//				//同一市（包括管辖的区）
//				if(k.contains("xh_xh")||k.contains("mh_fh")){
//					city += vs.get();
//				}
//				//计算同一省
//				if(k.contains("mh_fh")){
//					area += vs.get();
//				}
				if(k.contains("zh_1")){
					counttime += vs.get();
				}
				if(k.contains("xh_1")){
					counttime += vs.get();
				}
				if(k.contains("mh_1")){
					counttime += vs.get();
				}			
			}
			//省份统计相关
			if(k.contains("zh_zh")){
				context.write(key, new IntWritable(province));
			}
			if(k.contains("zh_1")){
				context.write(key, new IntWritable(counttime));
			}
			if(k.contains("xh_xh")){
				context.write(key, new IntWritable(city));
			}
			if(k.contains("xh_1")){
				context.write(key, new IntWritable(counttime));
			}
			if(k.contains("mh_fh")){
				context.write(key, new IntWritable(area));
			}
			if(k.contains("mh_1")){
				context.write(key, new IntWritable(counttime));
			}
	
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}
}
